package forgetpasswd

import (
	"context"

	"server-go/api/reward/internal/svc"
	"server-go/api/reward/internal/types"
	"server-go/rpc/reward/types/reward"

	"github.com/zeromicro/go-zero/core/logx"
)

type DoForgetPasswdLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDoForgetPasswdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DoForgetPasswdLogic {
	return &DoForgetPasswdLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DoForgetPasswdLogic) DoForgetPasswd(req *types.DoForgetPasswdInput) (resp *types.DoForgetPasswdOutput, err error) {
	resp = new(types.DoForgetPasswdOutput)
	res, err := l.svcCtx.RewardRpc.DoForgetPasswd(l.ctx, &reward.DoForgetPasswdInput{
		Email:    req.Email,
		Password: req.PassWord,
		Captcha:  req.Captcha,
	})
	if err != nil {
		return resp, err
	}
	resp.Message = &types.DoForgetPass{
		Success:      res.Success,
		CaptchaError: res.CaptchaError,
		EmailError:   res.EmailError,
	}
	return resp, nil
}
